package kr.hkit.powerjava.chapter10;

import java.util.Arrays;
import java.util.Random;

public class LottoGeneric2 {
	private boolean[] lotto ;
	private Random rnd;
	private static final int SIZE = 6;
	public LottoGeneric2() {
		this.lotto = new boolean[45];
		this.rnd = new Random();
	}
	
	public void getLottoNums(int cnt) {
		for(int i = 0; i<cnt; i++) {
			getLottoNum();
		}
	}
	
	public void initLotto() {
		for(int i = 0; i<lotto.length; i++ ) {
			lotto[i] = false;
		}
	}
	
	public void getLottoNum() {
		int num = -1;
		initLotto();
		for (int i = 0; i < SIZE; i++) {
			num = rnd.nextInt(45);
			if(lotto[num]) {//중복된 값이 2개
				i--;
			} else {// ㄴㄴ
				lotto[num] = true;
			}
		}
		prnLottoNum();
	}
	
	public void prnLottoNum() {
		for (int i = 0; i < lotto.length; i++) {
			if(lotto[i]) {
				System.out.printf("%3d", i+1);
			}
		}
		System.out.println();
	}
	
	@Override
	public String toString() {
		return "LottoGeneric2 [lotto=" + Arrays.toString(lotto) + "]";
	}

	public static void main(String[] args) {
		LottoGeneric2 lotto = new LottoGeneric2();

		lotto.getLottoNums(3);

	}
	
}
